package com.wgtp.ssapp.model.adapters;

import java.util.ArrayList;

import com.wgtp.ssapp.R;
import com.wgtp.ssapp.model.Forum;
import com.wgtp.ssapp.model.SubForum;
import com.wgtp.ssapp.view.fontable.FontableTextView;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class ForumListAdapter extends ArrayAdapter<SubForum> {

	private ArrayList<SubForum> subForumList;
	
	public ForumListAdapter(Context context, int textViewResourceId, ArrayList<SubForum> subForumList) {
		super(context, textViewResourceId, subForumList);
		this.subForumList = subForumList;
	}
	
	
	public void setForumListData(ArrayList<SubForum> newList) {
		this.subForumList = newList;
		notifyDataSetChanged();
	}
	
	
	@Override
	public int getCount() {
		return subForumList.size();
	}
	
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View newView = convertView;
		
		//Creates a new list item from the XML resource
        if (newView == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            newView = vi.inflate(R.layout.forum_list_item_row, null);
        }
        
        SubForum currentSubForum = subForumList.get(position);
        
        if (currentSubForum != null) {
                FontableTextView titleText  = (FontableTextView) newView.findViewById(R.id.forum_list_title);
                FontableTextView descriptionText  = (FontableTextView) newView.findViewById(R.id.forum_list_description);
                
                if (titleText != null) 
                	titleText.setText(currentSubForum.getName());
                
                if (descriptionText != null) 
                	descriptionText.setText(currentSubForum.getDescription());
             
        }
        
        return newView;
	}
	
}
